#include "mailsettingsdialog.h"
#include "ui_mailsettingsdialog.h"

#include <QSettings>

MailSettingsDialog::MailSettingsDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::MailSettingsDialog)
{
    ui->setupUi(this);
    init();
}

MailSettingsDialog::~MailSettingsDialog()
{
    delete ui;
}

void MailSettingsDialog::init()
{
    QSettings s;
    ui->fromEdit->setText(s.value(MAIL_FROM).toString());
    ui->serverEdit->setText(s.value(MAIL_SERVER).toString());
    ui->nameEdit->setText(s.value(MAIL_USERNAME).toString());
    ui->pwEdit->setText(s.value(MAIL_PASSWORD).toString());
    ui->subjectEdit->setText(s.value(MAIL_SUBJECT).toString());
    ui->bodyEdit->setHtml(s.value(MAIL_BODY).toString());
}

void MailSettingsDialog::on_okButton_clicked()
{
    QSettings s;
    s.setValue(MAIL_FROM, ui->fromEdit->text());
    s.setValue(MAIL_SERVER, ui->serverEdit->text());
    s.setValue(MAIL_USERNAME, ui->nameEdit->text());
    s.setValue(MAIL_PASSWORD, ui->pwEdit->text());
    s.setValue(MAIL_SUBJECT, ui->subjectEdit->text());
    s.setValue(MAIL_BODY, ui->bodyEdit->toHtml());
    accept();
}
